﻿
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Music</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link href="~/lib/layui/css/layui.css" rel="stylesheet" />
</head>
<body>

    <table class="layui-hide" id="test" lay-filter="test"></table>
    <script id="toolbarDemo" type="text/html">
        <div class="layui-btn-container">
            <button class="layui-btn layui-btn-normal" lay-event="add">添加</button>
        </div>
    </script>

    <script id="barDemo" type="text/html">
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    </script>
    <script src="~/lib/layui/layui.js"></script>
    <script src="~/js/jquery.min.js"></script>
    <script>
        layui.use('table', function () {
            var table = layui.table;
            table.render({
                elem: '#test'
                , url: '/Product/SearchTP'
                , toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
                , defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                    title: '提示'
                    , layEvent: 'LAYTABLE_TIPS'
                    , icon: 'layui-icon-tips'
                }]
                , title: '数据表'
                , id: 'testReload'
                , cols: [[
        { type: 'checkbox', fixed: 'left' }
                    , { field:'ImageNames', title:'图片名称', width:120, edit: 'text'}
                    , { field: 'Image', title: '图片', width: 100, templet: '<div><img src="{{d.Image}}"/></div>' }
        , { fixed: 'right', title: '操作', toolbar: '#barDemo', width: 150 }
    ]]
      , page: true
      , id: 'testReload'
            });

            table.on('toolbar(test)', function (obj) {
                var checkStatus = table.checkStatus(obj.config.id);
                switch (obj.event) {
                    case 'add':
                        layer.open({
                            type: 2
                            , area: ["40%", "60%"]
                            , content: '/Product/SCTP'
                            , end: function () {
                                tableIns.reload({
                                    where: {
                                        name: $("#name").val
                                    }
                                })
                            }
                        });
                        break;
        };
            });
        table.on('tool(test)', function (obj) {
            var data = obj.data;
         if (obj.event === 'edit') {

             var Id = data['Id']
                layer.open({
                    type: 2
                    , area: ["40%", "60%"]
                    , content: '/Product/BJ?Id=' + Id
                    , end: function () {
                        tableIns.reload({
                            where: {
                                name: $("#name").val
                            }
                        })
                    }
                });
            }

            });

        });
        active = {
            reload: function () {
                table.reload('testReload', {
                    page: {
                        curr: 1
                    }
                    , where: {

                    }
                }, 'data');

            }

        };
        $('.demoTable .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    </script>
</body>
</html>